<template>
   <div class="app-container">
    <set-header @query="data=>tableData=data"/>
    <!--表格渲染-->
  <el-table :data="tableData" stripe size="small" class="table-container">
  <el-table-column type="index" width="50px" align="center" label="序号"></el-table-column>
  <el-table-column prop="noticeTitle" label="标题" align="center"></el-table-column>
  <el-table-column prop="noticeContent" label="公告内容" align="center" show-overflow-tooltip></el-table-column>
  <el-table-column prop="userName" label="发布者" align="center"></el-table-column>
  <el-table-column>
        <template slot-scope="scope">
        <el-button size="mini"  @click="handleEdit(scope.row.id)">查看</el-button>
          <el-popover
            :ref="scope.row.id"
            placement="top"
            width="180">
            <p>确定删除本条数据吗？</p>
            <div style="text-align: right; margin: 0">
              <el-button size="mini" type="text" @click="$refs[scope.row.id].doClose()">取消</el-button>
              <el-button type="primary" size="mini" @click="subDelete(scope.row.id)">确定</el-button>
            </div>
            <el-button slot="reference" type="danger" size="mini">删除</el-button>
          </el-popover>
        </template>
      </el-table-column>
    </el-table>

    <!--分页组件-->
    <el-pagination
      background
      :page-count="totalPages"
      :page-size="pageSize"
      :current-page="currentPage"
      style="margin-top:8px; float:right"
      layout="prev,pager,next"
      @current-change="pageChange"/>

   <set-dialog ref="dlg" :diglogStatus="diglogStatus"  @close="diglogStatus=false"/>
   </div>
</template>

<script type="text/ecmascript-6">
import {getUserInfo} from '~utils/sessionStorage';
import {create, findAllDto, deleteNotice} from '@/api/notice'
import SetHeader from './module/SetHeader'
import SetDialog from './module/SetDialog'
export default {
  data() {
    return {
      costForm:{},
      tableData: [],
      currentPage:1,
      totalPages:1,
      pageSize:10,
      diglogStatus:false
    }
  },

  created() {
   this.getList()
  },
  mounted() {

    //   this.getData().then(response => {
    //   this.tableData = response.data.data.content
    // })
   },
   //计算属性 监听vuex中的数据
  //  computed: {
  //     ...mapState({
  //        tableData: state => state.costSet.table.data,
  //        pageCount: state => state.costSet.table.pageCount,
  //        pageSize: state => state.costSet.table.pageSize,
  //        currentPage: state => state.costSet.table.currentPage,
  //     })
  //  },
  components: {
      SetHeader,
      SetDialog,
  },
  methods: {
    getList(){
    findAllDto({"page":this.currentPage-1,"size":this.pageSize}).then(response => {
      this.tableData = response.content
      this.totalPages=response.totalPages
    })
    },
    // ...mapActions({
    //     findCostAll: 'costSet/findCostAll',
    //     deleteCostSet: 'costSet/deleteCostSet',
    //     editDialog: 'costSet/editDialog',
    // }),
    handleEdit(id){
        this.diglogStatus=true
        this.$nextTick(()=>{

          this.$refs.dlg.init(id)
        })
    },
    pageChange(currPage){
      this.currentPage = currPage
      this.getList()
      //  this.findAllDto({"page":this.currPage-1,"size":this.pageSize});
    },
    subDelete(id){
      // this.deleteCostSet(id).then(()=>{  deleteNotice
        deleteNotice(id).then(()=>{
        this.$refs[id].doClose();
        this.$notify({
          title: '删除成功',
          type: 'success',
          duration: 1500,
        }) ;
        this.getList()
      }).catch(err => {
          this.$refs[id].doClose();
      });
    },
    clearData(){
      Object.assign(this.$data, this.$options.data());
    },

  },
}

</script>

<style scoped lang="less">
</style>
